from computer import Ui_MainWindow
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow


class Cacular(QMainWindow, Ui_MainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.connecter()


    def ps_CE(self):
        self.lineEdit.clear()

    def ps_one(self):
        self.lineEdit.insert('1')

    def ps_two(self):
        self.lineEdit.insert('2')

    def ps_three(self):
        self.lineEdit.insert('3')

    def ps_four(self):
        self.lineEdit.insert('4')

    def ps_five(self):
        self.lineEdit.insert('5')

    def ps_six(self):
        self.lineEdit.insert('6')

    def ps_seven(self):
        self.lineEdit.insert('7')

    def ps_eight(self):
        self.lineEdit.insert('8')

    def ps_nine(self):
        self.lineEdit.insert('9')

    def ps_zero(self):
        self.lineEdit.insert('0')

    def ps_plus(self):
        self.lineEdit.insert('+')

    def ps_minus(self):
        self.lineEdit.insert('-')

    def ps_multi(self):
        self.lineEdit.insert('*')

    def ps_div(self):
        self.lineEdit.insert('/')

    def calcu(self):
        text = self.lineEdit.text()
        try:
            result = eval(text)
            self.lineEdit.setText(str(eval(text)))
        except:
            self.lineEdit.setText("输出错误，请按 CE 清空再次计算")

    def connecter(self):
        self.one.clicked.connect(self.ps_one)
        self.two.clicked.connect(self.ps_two)
        self.three.clicked.connect(self.ps_three)
        self.four.clicked.connect(self.ps_four)
        self.five.clicked.connect(self.ps_five)
        self.six.clicked.connect(self.ps_six)
        self.seven.clicked.connect(self.ps_seven)
        self.eight.clicked.connect(self.ps_eight)
        self.nine.clicked.connect(self.ps_nine)
        self.zero.clicked.connect(self.ps_zero)
        self.jia.clicked.connect(self.ps_plus)
        self.jian.clicked.connect(self.ps_minus)
        self.cheng.clicked.connect(self.ps_multi)
        self.chu.clicked.connect(self.ps_div)
        self.dengyu.clicked.connect(self.calcu)
        self.clear.clicked.connect(self.ps_CE)
                


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ca = Cacular()
    ca.show()
    sys.exit(app.exec_())
